package com.carrie.mdg.myviewtext.activity;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;

import com.carrie.mdg.myviewtext.R;
import com.carrie.mdg.myviewtext.utils.VersionUtil;
import com.example.blesdk.MainActivity;

import androidLib.activity.BaseActivity;

public class MyMainActivity extends BaseActivity {
    private static final String TAG = "MyMainActivity";
    private Button button, btnToWidgetText, btnToRecyclerText, btnToPercentLayoutTest,
            btnToChatActivity, btnToFragmentTest, btnToNewsTextActivity, btnToBroadcaseTestActivity,
            btnToLoginActivity, btnToFilePersistenceAc, btnToSharedPreferencesAc, btnToSQLiteTextAc,
            btnToLitePalTestAc, btnToNotificaTestAc, btnToCameraTextAc, btnToPlayAudioTextAc,
            btnToPlayVideoTextAc, btnToWebViewTextAc, btnToNetworkTextAc, btnToAndroidThreadAc,
            btnToServiceTextAc, btnToServiceBestPracAc, btnToMaterialTestAc, btnToMyViewTestAc,
            btnToRotateIVTextAc, btnToFSBLESDKTestAc;

    private static String[] permissions = new String[]{
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.ACCESS_COARSE_LOCATION,
    };
    public static final int PERMISSION_REQUEST_CODE = 0;


    public static void actionStart(Context context) {
        Intent intent = new Intent(context, MyMainActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void initVariables() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            Log.d(TAG, "initVariables: ");
            ActivityCompat.requestPermissions(this, permissions, PERMISSION_REQUEST_CODE);
            Log.d(TAG, "initVariables: ");
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        switch (requestCode) {
            case PERMISSION_REQUEST_CODE:
                if (grantResults.length > 0
                        && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                }
                break;
        }
    }

    @Override
    protected void initViews(Bundle savedInstanceState) {
        setContentView(R.layout.my_activity_main);
        button = findViewById(R.id.button);
        btnToWidgetText = findViewById(R.id.button_to_widget_text);
        btnToRecyclerText = findViewById(R.id.button_to_recycler_view_text);
        btnToPercentLayoutTest = findViewById(R.id.button_to_percent_layout_test);
        btnToChatActivity = findViewById(R.id.button_to_chat_activity);
        btnToFragmentTest = findViewById(R.id.button_to_fragment_text_activity);
        btnToNewsTextActivity = findViewById(R.id.button_to_news_test_activity);
        btnToBroadcaseTestActivity = findViewById(R.id.button_to_broadcase_test_activity);
        btnToLoginActivity = findViewById(R.id.button_to_login_activity);
        btnToFilePersistenceAc = findViewById(R.id.button_to_file_persistence_activity);
        btnToSharedPreferencesAc = findViewById(R.id.button_to_shared_preferences_activity);
        btnToSQLiteTextAc = findViewById(R.id.button_to_sqlite_test_ac);
        btnToLitePalTestAc = findViewById(R.id.button_to_litepal_test_ac);
        btnToNotificaTestAc = findViewById(R.id.button_to_notification_ac);
        btnToCameraTextAc = findViewById(R.id.button_to_camera_ac);
        btnToPlayAudioTextAc = findViewById(R.id.button_to_play_audio_ac);
        btnToPlayVideoTextAc = findViewById(R.id.button_to_play_video_ac);
        btnToWebViewTextAc = findViewById(R.id.button_to_web_view_ac);
        btnToNetworkTextAc = findViewById(R.id.button_to_network_ac);
        btnToAndroidThreadAc = findViewById(R.id.button_to_android_thread_ac);
        btnToServiceTextAc = findViewById(R.id.button_to_service_test_ac);
        btnToServiceBestPracAc = findViewById(R.id.button_to_service_best_practice_ac);
        btnToMaterialTestAc = findViewById(R.id.button_to_material_design_ac);
        btnToMyViewTestAc = findViewById(R.id.button_to_myview_ac);
        btnToRotateIVTextAc = findViewById(R.id.button_to_rotate_iv_ac);
        btnToFSBLESDKTestAc = findViewById(R.id.button_to_bsblesdk_ac);
    }

    @Override
    protected void initEvent() {
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toTestActivity();
            }
        });
        btnToWidgetText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WidgetTextActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToRecyclerText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RecyclerviewTextActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToPercentLayoutTest.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PercentLayoutTextActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToChatActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ChatActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToFragmentTest.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FragmentTestActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToNewsTextActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NewsTestActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToBroadcaseTestActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BroadcastTestActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToLoginActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LoginActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToFilePersistenceAc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FilePersistenceActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToSharedPreferencesAc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharePreferencesTestActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToSQLiteTextAc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SQLiteTestActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToLitePalTestAc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LitePalTextActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToNotificaTestAc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NotificationTestActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToCameraTextAc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CameraAlbumTestActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToPlayAudioTextAc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PlayAudioTestActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToPlayVideoTextAc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PlayVideoTestActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToWebViewTextAc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WebViewTestActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToNetworkTextAc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NetworkTestActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToAndroidThreadAc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AndroidThreadTestActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToServiceTextAc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ServiceTestActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToServiceBestPracAc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ServiceBestPracticeActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToMaterialTestAc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MaterialTestActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToMyViewTestAc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyViewTestActivity.actionStart(MyMainActivity.this);
            }
        });
        btnToRotateIVTextAc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RotateImageViewTest.actionStart(MyMainActivity.this);
            }
        });
        btnToFSBLESDKTestAc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                FSBLESDKTestActivity.actionStart(MyMainActivity.this);
                Intent intent = new Intent(MyMainActivity.this, MainActivity.class);
                MyMainActivity.this.startActivity(intent);
            }
        });
    }

    @Override
    protected void loadData() {

    }

    private void toTestActivity() {
        TextActivity.actionStart(this, "data1", "data2");
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return super.onTouchEvent(event);
    }
}
